package cn.gson.springboot.model.service;

import cn.gson.springboot.model.dao.EmployeeDao;
import cn.gson.springboot.model.mapper.EmployeeMapper;
import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Job;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
@Transactional(rollbackFor = Exception.class)
public class EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;

    @Autowired
    EmployeeDao employeeDao;

    //查找所有员工
    public List<Employee> findAllEmp(String search){
        return employeeMapper.findAllEmp(search);
    }
    //保存新增/修改的员工
    @Transactional(transactionManager = "transactionManager")
    public void saveEmp(Employee employee){
        employeeDao.save(employee);
    }

    public List<Employee> selectAllEmp(){
        return employeeMapper.selectAllEmp();
    }

    public List<Employee> selectAllBoss(){
        return employeeMapper.selectAllBoss();
    }

    public Employee findEmp(Integer empId){
        return employeeMapper.findEmp(empId);
    }

    public List<Employee> findAllEmpByFuzzy(String empName){
        return employeeMapper.findAllEmpByFuzzy(empName);
    }

    // 删除员工
    public void deleteEmp(Integer empId){
        employeeDao.deleteById(empId);
    }


    public List<Employee> findDeptEmp(Integer deptId){
        return employeeMapper.findDeptEmp(deptId);
    }
    public void updateEmpImg(String pic,Integer empId){
        employeeMapper.updateEmpImg(pic,empId);
    }
}
